//
//  FBDMenuViewController.m
//  baodongPro
//
//  Created by feng on 16/3/10.
//  Copyright © 2016年 proper. All rights reserved.
//
/**
 *      @author 冯宝东
 *
 *      冯宝东封装的FBDMenuViewController
 *
 *
 */

#define MenuCellIndentifier  @"MenuCellIndentifier"
#import "FBDMenuViewController.h"
#import "FBDTabBarViewController.h"
#import "UIView+FBDQuickCreateUI.h"
@interface FBDMenuViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) FBDTabBarViewController* myTabBarVC;
@property (nonatomic,strong) UITableView* myTableView;

@property (nonatomic,assign) BOOL isOpenMenu;
@end

@implementation FBDMenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor=[UIColor brownColor];
    _myTabBarVC=[[FBDTabBarViewController alloc] init];
    [self addChildViewController:_myTabBarVC];
    
    
    
    _myTableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH) style:UITableViewStyleGrouped];
    _myTableView.backgroundColor=[UIColor whiteColor];
    _myTableView.delegate=self;
    _myTableView.dataSource=self;
    [_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:MenuCellIndentifier];

    UILabel* headTipLabel=[self.view fbd_quickCreateUILabelWithFrame:CGRectMake(0, 0, ScreenW, 130)];
    headTipLabel.text=@"\nFBDMenu \n@Copy Right \nFengBaoDong";
    headTipLabel.numberOfLines=0;
    headTipLabel.textColor=[UIColor redColor];
    headTipLabel.font=[UIFont systemFontOfSize:23];
    _myTableView.tableHeaderView=headTipLabel;
    [self.view addSubview:_myTableView];
    [self.view addSubview:_myTabBarVC.view];
    
    
    
    
    
    
}
-(void)menuItemBarPressed:(id)sender
{
    self.isOpenMenu=!self.isOpenMenu;
    if (_isOpenMenu)
    {
        [self openFBDMenuView];
    }else
    {
        [self closeFBDMenuView];
    
    }
    NSLog(@"menu 按钮被店家了");


}
-(void)mySwipGestureDidSwiped:(UISwipeGestureRecognizer*)sender
{
 
    
    
    if (sender.direction==UISwipeGestureRecognizerDirectionRight)
    {
        NSLog(@"UISwipeGestureRecognizerDirectionRight");
        [self openFBDMenuView];
        self.isOpenMenu=YES;
    }else if (sender.direction==UISwipeGestureRecognizerDirectionLeft)
    {
        NSLog(@"UISwipeGestureRecognizerDirectionLeft");
        [self closeFBDMenuView];
        self.isOpenMenu=NO;
    }
    
}

// 打开FBDMenuView 视图
-(void)openFBDMenuView
{
    [UIView animateWithDuration:0.3 animations:^{
        
        [_myTabBarVC.view setView_orignX:ScreenW/2.0];
        
        
    }];



}
// 关闭FBDMenuView 视图
-(void)closeFBDMenuView
{
    [UIView animateWithDuration:0.3 animations:^{
        
        [_myTabBarVC.view setView_orignX:0/2.0];
        
        
    }];


}

#pragma mark ---------------UITableViewDelegate&&UITableViewDataSource


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return 10;

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:@"MenuCellIndentifier"];
    cell.backgroundColor=[cell randomColor];
    cell.textLabel.text=[NSString stringWithFormat:@"Menu for :%ld",indexPath.row];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    [self  menuItemBarPressed:nil];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
